<div class="container-fluid">
    <h1>News index</h1>
    <?php
    $news = $viewModel->get('News');

    $ctg = $viewModel->get("categories");
    
    include 'views/Include/alert.php';
    ?>
    <form class="form-horizontal" method="POST">
        <div class="control-group">
            <label class="control-label" for="inputCategoriesID">Category: </label>
            <div class="controls">
                <select id="inputNewsCategoriesBySch" name="category_id">
                    <option value="-1">Select Category</option>
                    <?php
                    foreach ($ctg as $category) {
                        echo "<option value='" . $category->category_id . "'>" . $category->category_name . "</option>";
                    }
                    ?>
                </select>
            </div>
        </div>
    </form>
    <form action="<?php echo BASE_URL . 'news/delete'; ?>" method="POST" onsubmit="return ConfirmChoiceDeleteMulti();">
        <a class="btn btn-primary" href="<?php echo BASE_URL . 'news/create' ?>">Add new</a>
        <button type="submit" class="btn btn-danger">Delete</button>
        <?php
        if ($news == NULL) {
            echo 'No result';
        } else {
            ?>
            <table class="table table-striped" id="tablePagination">
                <thead>
                    <tr>
                        <th></th>
                        <th>News ID</th>
                        <th>Title</th>
                        <th>Categories Name</th>
                        <th>Status</th>
                        <th>Content</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody id="news-search">
                    <?php foreach ($news as $news) { ?>
                        <tr>
                            <td><input name="news_id[]" type="checkbox" news_id="checkboxnews_id[]" value="<?php echo $news->news_id; ?>" /></td>
                            <td><?php echo $news->news_id; ?></td>
                            <td><?php echo $news->title; ?></td>
                            <td><?php echo $news->category_name; ?></td>
                            <td><?php echo ($news->status == 1) ? "Active" : "Deacive"; ?></td>
                            <td><?php echo $news->content; ?></td>

                            <td>
                                <div class="btn-group">
                                    <a class="btn" href="<?php echo BASE_URL . 'News/Update/' . $news->news_id; ?>"><i class="icon-edit"></i></a>
                                    <a class="btn" href="" onclick="ConfirmChoiceDelete('<?php echo BASE_URL . 'News/Delete/' . $news->news_id; ?>');return false;"><i class="icon-remove-sign"></i></a>
                                </div>
                            </td>
                        </tr>
                    <?php } ?>
                </tbody>
            </table>
        <?php } ?>
        <div id="smart-paginator"></div>
    </form>
</div>